/******************************************************************************
	Cobalt - utility libraries for building XNA games
	Copyright (C) 2008 Philip Djonov

	This program is free software; you can redistribute it and/or modify it
	under the terms of the GNU General Public License as published by the Free
	Software Foundation; either version 2 of the License, or (at your option)
	any later version.

	This program is distributed in the hope that it will be useful, but
	WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
	or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
	for more details.

	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the
	
		Free Software Foundation, Inc.
		51 Franklin Street, Fifth Floor
		Boston, MA  02110-1301, USA.
******************************************************************************/

using System;

namespace Cobalt.Content
{

	public struct Matrix2x3
	{
		public float M11, M12, M13;
		public float M21, M22, M23;

		public Matrix2x3( float m11, float m12, float m13, float m21, float m22, float m23 )
		{
			M11 = m11; M12 = m12; M13 = m13;
			M21 = m21; M22 = m22; M23 = m23;
		}

		public static Matrix2x3 Identity { get { return new Matrix2x3( 1, 0, 0, 0, 1, 0 ); } }

		public static Matrix2x3 operator *( Matrix2x3 a, Matrix2x3 b )
		{
			Matrix2x3 ret;

			ret.M11 = a.M11 * b.M11 + a.M12 * b.M21;
			ret.M12 = a.M11 * b.M12 + a.M12 * b.M22;
			ret.M21 = a.M21 * b.M11 + a.M22 * b.M21;
			ret.M22 = a.M21 * b.M12 + a.M22 * b.M22;
			
			ret.M13 = a.M11 * b.M11 + a.M12 * b.M21 + a.M13;
			ret.M23 = a.M21 * b.M12 + a.M22 * b.M22 + a.M23;

			return ret;
		}

		public override int GetHashCode()
		{
			return M11.GetHashCode() + M12.GetHashCode() + M13.GetHashCode() +
				M21.GetHashCode() + M22.GetHashCode() + M23.GetHashCode();
		}

		public override bool Equals( object obj )
		{
			return obj is Matrix2x3 && this == (Matrix2x3)obj;
		}

		public static bool operator ==( Matrix2x3 a, Matrix2x3 b )
		{
			return a.M11 == b.M11 && a.M12 == b.M12 && a.M13 == b.M13 &&
				a.M21 == b.M21 && a.M22 == b.M22 && a.M23 == b.M23;
		}

		public static bool operator !=( Matrix2x3 a, Matrix2x3 b )
		{
			return a.M11 != b.M11 || a.M12 != b.M12 || a.M13 != b.M13 ||
				a.M21 != b.M21 || a.M22 != b.M22 || a.M23 != b.M23;
		}
	}

}